<template>
	<view class="main">
		<view class="top uni-flex uni-align-items-c">
			<view class="lf">
				<image v-if="userFindData.face" :src="imgUrl + userFindData.face" mode=""></image>
			</view>
			<view class="rt uni-flex uni-flex-direction-c uni-justify-content-c">
				<view class="uni-flex uni-justify-content-sb">
					<view class="name">
						{{userFindData.username}}
						<template v-if="userFindData.role==1">（总包部）</template>
						<template v-else-if="userFindData.role==2">（项目人员）</template>
						<template v-else-if="userFindData.role==3">（劳务人员）</template>
						<template v-else-if="userFindData.role==4">（访客）</template>
						<template v-else-if="userFindData.role==5">（监理）</template>
					</view>
					<view>
						<text class="blue" v-if="userFindData.status == 0">待认证</text>
						<text class="blue" v-if="userFindData.status == 1">已认证</text>
						<text class="red" v-if="userFindData.status == 2">认证失败</text>
					</view>
				</view>
			</view>
		</view>

		<view class="block">
			<view class="title">
				必填信息
			</view>
			<view class="row uni-flex" v-if="userFindData.username">
				<view class="lf">
					姓名
				</view>
				<view class="rt">
					{{userFindData.username?userFindData.username:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBids">
				<view class="lf">
					标段
				</view>
				<view class="rt">
					{{userFindData.userBids?userFindData.userBids:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userSites">
				<view class="lf">
					工地
				</view>
				<view class="rt">
					{{userFindData.userSites?userFindData.userSites:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.idcard">
				<view class="lf">
					证件信息
				</view>
				<view class="rt">
					{{userFindData.idcard?userFindData.idcard:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.phone">
				<view class="lf">
					联系电话
				</view>
				<view class="rt">
					{{userFindData.phone?userFindData.phone:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.education">
				<view class="lf">
					学历
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.education?userFindData.userBaseInfo.education:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.homeAddress">
				<view class="lf">
					家庭住址
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.homeAddress?userFindData.userBaseInfo.homeAddress:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.contact">
				<view class="lf">
					紧急联系人
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.contact?userFindData.userBaseInfo.contact:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.tel">
				<view class="lf">
					紧急联系人电话
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.tel?userFindData.userBaseInfo.tel:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.profession.name">
				<view class="lf">
					专业
				</view>
				<view class="rt">
					{{userFindData.profession.name?userFindData.profession.name:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.job.name">
				<view class="lf">
					工种
				</view>
				<view class="rt">
					{{userFindData.job.name?userFindData.job.name:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.political">
				<view class="lf">
					政治面貌
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.political?userFindData.userBaseInfo.political:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.jobTime">
				<view class="lf">
					参加工作时间
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.jobTime?userFindData.userBaseInfo.jobTime:'-'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBaseInfo.year">
				<view class="lf">
					相关工作年限
				</view>
				<view class="rt">
					{{userFindData.userBaseInfo.year?userFindData.userBaseInfo.year + '年' : '-'}}
				</view>
			</view>
			<view class="row uni-flex">
				<view class="lf w70">
					14天内是否经过中高风险区
				</view>
				<view class="rt w30">
					{{userFindData.highRiskArea14?'是' : '否'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.highRiskAreaTime">
				<view class="lf w70">
					哪天经过中高风险区
				</view>
				<view class="rt w30">
					{{userFindData.highRiskAreaTime}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.highRiskAreaCity">
				<view class="lf w70">
					经过哪个中高风险区
				</view>
				<view class="rt w30">
					{{userFindData.highRiskAreaCity}}
				</view>
			</view>
			<view class="row uni-flex">
				<view class="lf w70">
					是否接种新冠疫苗
				</view>
				<view class="rt w30">
					{{userFindData.covid19?'是' : '否'}}
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.covid19Time">
				<view class="lf w70">
					接种时间
				</view>
				<view class="rt w30">
					{{userFindData.covid19Time}}
				</view>
			</view>
		</view>

		<view class="block">
			<view class="title">
				非必填信息
			</view>
			<view class="row uni-flex" v-if="userFindData.userBank.bankNum">
				<view class="lf">
					银行卡号
				</view>
				<view class="rt">
					<text v-if="userFindData.userBank.bankNum">{{userFindData.userBank.bankNum}}</text>
					<text v-else>-</text>
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.userBank.bank">
				<view class="lf">
					银行名称
				</view>
				<view class="rt">
					<text v-if="userFindData.userBank.bank">{{userFindData.userBank.bank}}</text>
					<text v-else>-</text>
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.jobCertificate.name">
				<view class="lf">
					作业证书
				</view>
				<view class="rt">
					<text v-if="userFindData.jobCertificate.name">{{userFindData.jobCertificate.name}}</text>
					<text v-else>-</text>
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.jobCertificate.type">
				<view class="lf">
					证件类别
				</view>
				<view class="rt">
					<text v-if="userFindData.jobCertificate.type">{{userFindData.jobCertificate.type}}</text>
					<text v-else>-</text>
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.jobCertificate.license">
				<view class="lf">
					证件号码
				</view>
				<view class="rt">
					<text v-if="userFindData.jobCertificate.license">{{userFindData.jobCertificate.license}}</text>
					<text v-else>-</text>
				</view>
			</view>
			<view class="row uni-flex" v-if="userFindData.jobCertificate.time">
				<view class="lf">
					证件有效期
				</view>
				<view class="rt">
					<text v-if="userFindData.jobCertificate.time">{{userFindData.jobCertificate.time}}</text>
					<text v-else>-</text>
				</view>
			</view>
			<view class="row u-flex" v-if="userFindData.certificateImage.length>0">
				<view class="lf">
					证书
				</view>
				<view class="r" style="text-align: left;">
					<image @click="previewImg(index)" class="img" v-for="(item,index) in userFindData.certificateImage"
						:src="imgUrl + item" mode=""></image>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import config from '@/common/config.js';
	export default {
		data() {
			return {
				userFindData: null, //用户详情
				imgUrl: '',
				imgUrlList: [], //图片预览
			}
		},
		onLoad(options) {
			this.userFind(options.id);
			this.imgUrl = config.imgUrl + '/';
		},
		methods: {
			// 获取用户详情
			userFind(id) {
				this.$u.api.userFind({
					id: id
				}).then(res => {
					if (res.code == 0) {
						res.data.userBids = res.data.bid.map(item => {
							return item.name;
						}).join("、");
						res.data.userSites = res.data.userSite.map(item => {
							return item.site.name;
						}).join("、");
						this.userFindData = res.data;
						this.imgUrlList = res.data.certificateImage;
					}
				})
			},
			// 预览图片多张
			previewImg(index) {
				let imgsArray = [];
				for (let i = 0; i < this.imgUrlList.length; i++) {
					if (this.imgUrlList[i].length > 0) {
						imgsArray.push(config.imgUrl + '/' + this.imgUrlList[i]);
					}
				}

				// #ifdef MP
				uni.previewImage({
					current: index,
					urls: imgsArray,
					indicator: 'number',
					loop: true
				});
				// #endif

				// #ifndef MP
				uni.previewImage({
					current: index,
					urls: imgsArray,
					indicator: 'number',
					loop: true
				});
				// #endif
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding-bottom: 140rpx;

		.top {
			height: 138rpx;
			background: #FFFFFF;
			padding: 0 32rpx;

			.lf {
				width: 100rpx;
				height: 100rpx;
				border-radius: 20rpx;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.rt {
				margin-left: 16rpx;
				width: 570rpx;

				.name {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					width: 480rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.blue {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #30A1FF;
				}

				.red {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #FF0000;
				}

				.section-construction-site {

					.section,
					.construction-site {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #333333;
						margin-top: 18rpx;
					}

					.section {
						margin-right: 66rpx;
					}
				}
			}
		}

		.block {
			padding: 32rpx;
			background: #fff;
			margin-top: 16rpx;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.row {
				margin-top: 32rpx;

				.lf {
					width: 196rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #737373;
				}

				.rt {
					width: 490rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					text-align: right;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;

					.red {
						color: #FF0000;
					}

					.img {
						width: 176rpx;
						height: 176rpx;
						margin-bottom: 20rpx;
					}

					.img:not(:nth-child(2n+2)) {
						margin-right: 20rpx;
					}
				}

				.r {
					width: 490rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;

					.img {
						width: 176rpx;
						height: 176rpx;
						margin-bottom: 20rpx;
					}

					.img:not(:nth-child(2n+2)) {
						margin-right: 20rpx;
					}
				}

				.w70 {
					width: 70%;
				}

				.w30 {
					width: 30%;
				}
			}
		}
	}
</style>
